var SITEURL = './';
var SERVERURL = 'http://juanzhu.zhoukezhang.com/';
var TOPHEIGHT = 70;
var zhiye = new Array( '0','无业','学生','模特','空姐','计算机/互联网/通信', '生产/工艺/制造', '医疗/护理/制药', '金融/银行/投资/保险', '商业/服务业/个体经营',
 '文化/广告/传媒', '娱乐/艺术/表演', '律师/法务', '教育/培训', '公务员/行政/事业单位' );
var min_zhiye = new Array( '0','无业','学生','模特','空姐','IT', '制造', '医疗', '金融', '商业',
 '文化', '艺术', '律师', '教育', '行政' );
function toast( text ){
	api.toast({
	    msg: text,
	    duration: 2000,
	    location: 'bottom'
	});
}
function fh(){
	var winHeight = api.winHeight;
	var fh = winHeight - 130;
	return fh;
}
function open_user_page( id ){
	api.openWin({
	    name: 'user_page',
	    url: 'http://yuanzhuta.zhoukezhang.com/html/user_index.html',
	    vScrollBarEnabled: false,
	    allowEdit: true,
	    reload: true,
	    pageParam: {
	        id: id
	    }
	});
}
function msg_page( frame_name, user_id ){
	api.openFrame({
	    name: frame_name, 
		url: 'http://yuanzhuta.zhoukezhang.com/html/'+frame_name+'.html',
	    rect: {
	        x: 0,
	        y: api.winHeight - 230,
	        w: api.winWidth,
	        h: 170
	    },
	    pageParam: {
	    	id: user_id
	    },
	    bounces: true,
	    bgColor: 'rgba(0,0,0,0)',
	    vScrollBarEnabled: true,
	    hScrollBarEnabled: true,
	    reload: true
	});
}
function goto_frame( frame_name, y, height, class_name ){
	var fHeight = height ? height : api.winHeight,
		fy = y ? y : $api.dom('header').offsetHeight;
	api.openFrame({
	    name: frame_name, 
		url: 'http://yuanzhuta.zhoukezhang.com/html/'+frame_name+'.html',
	    rect: {
	        x: 0,
	        y: fy,
	        w: api.winWidth,
	        h: fHeight
	    },
	    pageParam: {
	    	y: y,
		    height: height,
	    },
	    bounces: true,
	    bgColor: 'rgba(0,0,0,0)',
	    vScrollBarEnabled: true,
	    hScrollBarEnabled: true,
	    reload: true
	});
	head_foot_active( class_name );
}
function  goto_frame_noreload( frame_name, y, height, class_name ){
	var fHeight = height ? height : api.winHeight,
		fy = y ? y : $api.dom('header').offsetHeight;
	api.openFrame({
	    name: frame_name, 
		url: 'http://yuanzhuta.zhoukezhang.com/html/'+frame_name+'.html',
	    rect: {
	        x: 0,
	        y: fy,
	        w: api.winWidth,
	        h: fHeight
	    },
	    pageParam: {
	    	y: y,
		    height: height,
	    },
	    bounces: true,
	    bgColor: 'rgba(0,0,0,0)',
	    vScrollBarEnabled: true,
	    hScrollBarEnabled: true,
	    reload: false
	});
	head_foot_active( class_name );
}
function  open_frame_val( frame_name, field, val, shuaxin){
	var fHeight = fh(),
		fy = TOPHEIGHT,
		reload = shuaxin ? 'true' : 'false';
	api.openFrame({
	    name: frame_name, 
		url: 'http://yuanzhuta.zhoukezhang.com/html/'+frame_name+'.html',
	    rect: {
	        x: 0,
	        y: fy,
	        w: api.winWidth,
	        h: fHeight
	    },
	    pageParam: {
	    	field: field,
		    val: val
	    },
	    bounces: true,
	    bgColor: 'rgba(0,0,0,0)',
	    vScrollBarEnabled: true,
	    hScrollBarEnabled: true,
	    reload: reload
	});
}
function l_r_frame(frame_name, y, height){
	goto_frame( frame_name, y, height);
	api.closeFrame();
}
function head_foot_active( class_name ){
	$(".flex-wrap li span").removeClass("active");
	if( class_name ){
		$(".head-title li").removeClass("active");
		$("."+class_name).addClass("active");
		$("."+class_name).addClass("active");
	}
}
function check_mobile(s){
	var regu =/^[1][3|8|4|5|7][0-9]{9}$/;
	var re = new RegExp(regu);
	if (re.test(s)) {
		return true;
	}else{
		return false;
	}
}
function check_val( id, input ){
	var input = input ? true : false;
	if(input){
		var val = $("#"+id).val();
		if(val.length == 0){
			api.toast({
			    msg: '空值不保存',
			    duration: 1000,
			    location: 'bottom'
			});
			return false;
		}
		if(val == $api.getStorage('user_'+id)){
		api.toast({
		    msg: '无修改不保存',
		    duration: 1000,
		    location: 'bottom'
		});
		return false;
		}
	}else{
		if(id == $api.getStorage('user_'+id)){
		api.toast({
		    msg: '无修改不保存',
		    duration: 1000,
		    location: 'bottom'
		});
		return false;
		}
	}
	return true;
}
function select_date(){
	api.openPicker({
	    type: 'date_time',
	    date: '2014-05-01',
	    title: '选择时间'
	},function( ret, err ){
	    if( ret ){
	    	$("#birthday").val(ret.year+'-'+ret.month+'-'+ret.day);
	    }else{
	         alert( JSON.stringify( err ) );
	    }
	});
}
function set_login_user( user_info ){
	$api.setStorage('user_id',user_info.id);
	$api.setStorage('mobile',user_info.mobile);
	$api.setStorage('login_mobile',user_info.mobile);
	$api.setStorage('password',user_info.password);
	$api.setStorage('user_pic',user_info.img);
}

//点击两个返回键退出app
function exitApp(){
            api.addEventListener({
                name: 'keyback'
            }, function(ret, err){
                api.toast({
                        msg: '再按一次返回键退出'+api.appName,
                        duration:2000,
                        location: 'bottom'
                    });
                   
                    api.addEventListener({
                        name: 'keyback'
                    }, function(ret, err){
                        api.closeWidget({
                                id: 'A6904859772194',     //这里改成自己的应用ID
                                retData: {name:'closeWidget'},
                                silent:true
                            });
                    });
                   
                    setTimeout(function(){
                            exitApp();
                    },3000)
            });
		}